<?php

namespace App\Manage;


use App\Models\Order;
use App\Models\SiteInfo;
use App\Service\Base\Manage;

class OrderUserManage extends Manage
{

    // 基本配置
    public function initialize()
    {
        parent::initialize();

        $this->model = 'OrderUser';
    }

    // 列表
    // 添加
    // 修改
    // 软删除


    // 列表查询
    protected function listWhere()
    {
        $option      = $this->option();
        $where       = [];
        $bang        = [];
        $uid         = $option->getData('uid', 0, 'intval');
        $student_id  = $option->getData('student_id', 0, 'intval');
        $event_id    = $option->getData('event_id', 0, 'intval');
        $order_id    = $option->getData('order_id', 0, 'intval');
        $sex         = $option->getData('sex', null, 'intval');
        $age         = $option->getData('age', null, 'intval');
        $status      = $option->getData('status', null, 'intval');
        $old_id      = $option->getData('old_id', null, 'intval');
        $guardor     = $option->getData('guardor', null, 'trim');
        $mobile      = $option->getData('mobile', null, 'trim');
        $person_name = $option->getData('person_name', null, 'trim');
        $keyword     = $option->getData('keyword', null, 'trim');
        $isRefund    = $option->getData('is_refund', null, 'trim');

        $status_refund = $option->getData('status_refund', null, 'trim');
        if($uid){
            $bang[]  = 'uid';
            $where[] = ['uid', '=', $uid];
        }
        if($event_id){
            $bang[]  = 'event_id';
            $where[] = ['event_id', '=', $event_id];
        }
        if($order_id){
            $bang[]  = 'order_id';
            $where[] = ['order_id', '=', $order_id];
        }
        if($sex){
            $bang[]  = 'sex';
            $where[] = ['sex', '=', $sex];
        }

        if($isRefund){
            $bang[]  = 'is_refund';
            $where[] = ['is_refund', '=', $isRefund];
        }
        if($person_name){
            $bang    = false; // 设置不在缓存
            $where[] = ['person_name', 'like', "%".$person_name."%"];
        }
        if($mobile){
            $bang    = false; // 设置不在缓存
            $where[] = ['mobile', 'like', "%".$mobile."%"];
        }
        if($guardor){
            $bang    = false; // 设置不在缓存
            $where[] = ['guardor', 'like', "%".$guardor."%"];
        }
        if($keyword){
            $bang = false; // 设置不在缓存
            //$where[] = $this->orWhere('username|nickname|mobile', 'like', $keyword);
        }

        // 缓存
        $this->bang = $bang;

        return $where;
    }


    // 添加之前
    protected function _before_add()
    {
        $opt = $this->option();
        $uid = $opt->getData("uid", null, "intval");
        if(empty($uid)){
            return $this->_returnFail('请指定用户');
        }

        $data = [
            //'id'        => $opt->getData("id", null, "intval"),
            'uid'         => $uid,
            'order_id'    => $this->getData("order_id", null, "intval"),
            'event_id'    => $this->getData("event_id", null, "intval"),
            'student_id'  => $this->getData("student_id", null, "intval"),
            'order_uid'   => $this->getData("order_uid", null, "intval"),
            'person_name' => $this->getData("person_name", null, "trim"),
            'head_img'    => $this->getData("head_img", null, "trim"),
            'sex'         => $this->getData("sex", null, "intval"),
            'age'         => $this->getData("age", null, "intval"),
            'guardor'     => $this->getData("guardor", null, "trim"),
            'mobile'      => $this->getData("mobile", null, "trim"),
            'status'      => $this->getData("status", null, "intval"),
            'is_remind'   => $this->getData("is_remind", null, "intval"),
            //'ctime'     => $opt->getData("ctime", null, "intval"),
            //'mtime'     => $opt->getData("mtime", null, "intval"),
        ];


        return $data;
    }

    // 修改之前
    protected function _before_edit()
    {
        $opt  = $this->option();
        $data = [
            //'id'        => $opt->getData("id", null, "intval"),
            //'uid'         => $uid,
            //'order_id'    => $this->getData("order_id", null, "intval"),
            'event_id'    => $this->getData("event_id", null, "intval"),
            'student_id'  => $this->getData("student_id", null, "intval"),
            'order_uid'   => $this->getData("order_uid", null, "intval"),
            'person_name' => $this->getData("person_name", null, "trim"),
            'head_img'    => $this->getData("head_img", null, "trim"),
            'sex'         => $this->getData("sex", null, "intval"),
            'age'         => $this->getData("age", null, "intval"),
            'guardor'     => $this->getData("guardor", null, "trim"),
            'mobile'      => $this->getData("mobile", null, "trim"),
            'status'      => $this->getData("status", null, "intval"),
            'is_remind'   => $this->getData("is_remind", null, "intval"),
            //'ctime'     => $opt->getData("ctime", null, "intval"),
            //'mtime'     => $opt->getData("mtime", null, "intval"),
        ];

        return $data;
    }


}


